package top.codedance.iotp.server.net.initializer;

import top.codedance.iotp.common.handler.AbsractIdleHandler;
import top.codedance.iotp.common.protocol.CommonDecoderCodec;
import top.codedance.iotp.server.ServerApplication;
import top.codedance.iotp.server.net.TcpServer;
import top.codedance.iotp.server.net.handle.*;
import cd.io.netty.channel.ChannelInitializer;
import cd.io.netty.channel.socket.SocketChannel;
import cd.io.netty.handler.timeout.IdleStateHandler;

public class TcpChannelInitializer extends ChannelInitializer<SocketChannel> {
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        socketChannel.pipeline()
                .addLast("commonDecoderCodec", new CommonDecoderCodec(ServerApplication.getLogger(TcpServer.class)))
                .addLast("idleStateHandler", new IdleStateHandler(15, 0, 0))
                .addLast(new IdleChannelHandler(ServerApplication.getLogger(AbsractIdleHandler.class)))
                .addLast(new RSAEncryptChannelHandler())
                .addLast(new ConsoleReceptionHandler())
                .addLast(new ClientCommonHandler())
                .addLast(new AsyncClientCommonHandler())
                .addLast(new TcpCounterHandler());
    }
}
